package com.onion.utils.utils;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.List;

public class ListHelper {

    /**
     * List分段
     * @param listData
     * @param splitSize
     * @param <T>
     * @return
     */
    public static <T> List<List<T>> split(List<T> listData, int splitSize){
        List<List<T>> splitList = Lists.newArrayList();
        if(listData==null || listData.isEmpty() || splitSize<=0){
            return splitList;
        }
        int startIndex = 0;
        int endIndex = splitSize;
        while(startIndex < listData.size()){
            if(listData.size() > startIndex+splitSize){
                endIndex = startIndex + splitSize;
            }else{
                endIndex = listData.size();
            }
            List<T> curSubList = listData.subList(startIndex, endIndex);
            splitList.add(curSubList);

            startIndex = endIndex;
        }
        return splitList;
    }

    public static void main(String[] args){
        List<Integer> sourceList = new ArrayList<>();
        for(int i=0; i<50; i++){
            sourceList.add(i);
        }
        List<List<Integer>> result = split(sourceList, 100);
        System.out.println(".........");
    }

}